<template>
  <div>
    <user-form title="登录" @submit="isLogin">
      <template #default>
        <router-link class="register-a" to="/register">没有账号,去注册</router-link>
      </template>
    </user-form>
  </div>
</template>

<script>
import UserForm from '@/components/UserForm.vue'
import { loginAPI } from '@/api/user'
import { setToken } from '@/api/storage'
import { mapMutations } from 'vuex'
export default {
  name: 'LoginIndex',
  components: { UserForm },
  methods: {
    ...mapMutations('user', ['saveToken']),
    async isLogin (value) {
      const res = await loginAPI(value)
      if (res.data.code === 0) {
        setToken(res.data.token)
        await this.saveToken(res.data.token)
        this.$message.success('登录成功')
        this.$router.push('/')
      }
    }
  }
}
</script>

<style scoped>

</style>
